package com.kaizeli.website.entity;

import jakarta.persistence.*;
import lombok.Data;
import org.hibernate.annotations.Comment;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 项目验收单JPA实体类
 */
@Data
@Entity
@Table(name = "project_acceptance",
       indexes = {
           @Index(name = "idx_project_id", columnList = "projectId"),
           @Index(name = "idx_acceptance_date", columnList = "acceptanceDate"),
           @Index(name = "idx_status", columnList = "status"),
           @Index(name = "idx_priority", columnList = "priority")
       })
public class ProjectAcceptanceEntity {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    @Comment("主键ID")
    private Long id;
    
    @Column(name = "acceptance_no", length = 50, unique = true, nullable = false)
    @Comment("验收单编号")
    private String acceptanceNo;
    
    @Column(name = "project_id", nullable = false)
    @Comment("项目ID")
    private Long projectId;
    
    @Column(name = "project_name", length = 200)
    @Comment("项目名称（冗余字段）")
    private String projectName;
    
    @Column(name = "project_code", length = 100)
    @Comment("项目编号（冗余字段）")
    private String projectCode;
    
    @Column(name = "sub_project_name", length = 200)
    @Comment("子项目名称（冗余字段）")
    private String subProjectName;
    
    @Column(name = "contact_person", length = 100)
    @Comment("对接人（冗余字段）")
    private String contactPerson;
    
    @Column(name = "client", length = 200)
    @Comment("客户（冗余字段）")
    private String client;
    
    @Column(name = "department", length = 100)
    @Comment("部门（冗余字段）")
    private String department;
    
    @Column(name = "section", length = 100)
    @Comment("科室（冗余字段）")
    private String section;
    
    @Column(name = "contract_no", length = 100)
    @Comment("合同号（冗余字段）")
    private String contractNo;
    
    @Column(name = "acceptance_date", nullable = false)
    @Comment("验收时间点")
    private LocalDate acceptanceDate;
    
    @Column(name = "priority")
    @Comment("验收时间点优先级（1-最高，2-高，3-中，4-低，5-最低）")
    private Integer priority = 3;
    
    @Column(name = "acceptance_person_id")
    @Comment("验收人员ID")
    private Long acceptancePersonId;
    
    @Column(name = "acceptance_person_name", length = 100)
    @Comment("验收人员姓名（冗余字段）")
    private String acceptancePersonName;
    
    @Column(name = "acceptance_standard", columnDefinition = "TEXT")
    @Comment("验收标准")
    private String acceptanceStandard;
    
    @Column(name = "budget_amount", precision = 15, scale = 2)
    @Comment("预算金额")
    private BigDecimal budgetAmount = BigDecimal.ZERO;
    
    @Column(name = "acceptance_amount", precision = 15, scale = 2)
    @Comment("验收金额")
    private BigDecimal acceptanceAmount = BigDecimal.ZERO;
    
    @Column(name = "status", length = 50)
    @Comment("验收状态（待验收、验收中、已验收、验收失败）")
    private String status = "待验收";
    
    @Column(name = "acceptance_completion_time")
    @Comment("已验收时间")
    private LocalDateTime acceptanceCompletionTime;
    
    @Column(name = "attachment_urls", columnDefinition = "TEXT")
    @Comment("验收附件URL（多个用逗号分隔）")
    private String attachmentUrls;
    
    @Column(name = "remark", columnDefinition = "TEXT")
    @Comment("备注")
    private String remark;
    
    @Column(name = "create_time", nullable = false, updatable = false)
    @Comment("创建时间")
    private LocalDateTime createTime;
    
    @Column(name = "update_time", nullable = false)
    @Comment("更新时间")
    private LocalDateTime updateTime;
    
    @PrePersist
    protected void onCreate() {
        createTime = LocalDateTime.now();
        updateTime = LocalDateTime.now();
    }
    
    @PreUpdate
    protected void onUpdate() {
        updateTime = LocalDateTime.now();
    }
}
